package hotel.meituan.oversea.biz.task;

import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsStatusDetailVo;
import hotel.meituan.oversea.biz.service.MtHotelGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Slf4j
@Component
public class MeituanSaveUpdateGoodsStatusTableTask {
    private String timestamp = "Msugptt"+String.valueOf(System.currentTimeMillis());
    @Autowired
    private MtHotelGoodsService mtHotelGoodsService;
    @Autowired
    private RestTemplate restTemplate;

    //@Async 标识这个方法异步执行，可返回void或Future
    @Async
    public void executeSaveUpdateGoodsStatusTable(Map<String,MtHotelGoodsStatusDetailVo> allChangeGoodsAboutStatusMap, String thisHotelId){

        List<MtHotelGoodsStatusDetailVo> goodsList = new ArrayList<>();

        for (Map.Entry<String,MtHotelGoodsStatusDetailVo> c:allChangeGoodsAboutStatusMap.entrySet()){
            goodsList.add(c.getValue());
        }

        log.info("MeituanSaveUpdateGoodsPriceTableTask {} >>>>>>>>> 异步线程 更新 价格 库表  开始执行时间：{}",timestamp,DateUtil.getNowTime());
        if (null != goodsList && goodsList.size() > 0) {
            mtHotelGoodsService.saveGoodsStatus(goodsList,thisHotelId);
        }
    }

}
